package com.example.springcloud.alibaba.service.impl;

import com.example.springcloud.alibaba.dao.OrderDao;
import com.example.springcloud.alibaba.model.Order;
import com.example.springcloud.alibaba.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;
 /* @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;*/

    @Override
//    @Transactional
    public boolean create(Order order) {
        log.info("------>开始新建订单");
        //1 新建订单
        int index = orderDao.insert(order);
        log.info("------>订单微服务开始调用库存,做扣减Count");
        return index > 0;

/*      //2 扣减库存
        storageService.decrease(order.getProductId(),order.getCount());
        log.info("------>订单微服务开始调用库存,做扣减END");

        log.info("------>订单微服务开始调用账户,做扣减Money");
        //3 扣减账户
        accountService.decrease(order.getUserId(),order.getMoney());
        log.info("------>订单微服务开始调用账户,做扣减End");
        log.info("------>订单订单状态开始");
        //4 修改订单状态从0到1
        orderDao.update(order.getUserId(),0);
        log.info("------>修改订单状态结束");
        log.info("------>下订单结束了, 哈哈~");
        return true;*/
    }
}
